package org.bbelovic.devel.pexeso.gui;

import java.util.ArrayList;
import java.util.List;

public class Player {

    private final List<String> pairs = new ArrayList<String>();
    private final String name;
    private int actionPoints;
    private int scorePoints;

    public Player(String name) {
        this.actionPoints = 2;
        this.name = name;
    }

    public void decrementActionPoints() {
        --actionPoints;
    }
    
    public int getActionPoints() {
        return this.actionPoints;
    }

    public void addPair(final String flagName) {
        pairs.add(flagName);
    }

    public List<String> getPairs() {
        return this.pairs;
    }
    
    public void restoreActionPoints() {
        this.actionPoints = 2;
    }

    public int getScorePoints() {
        return this.scorePoints;
    }

    public String getName() {
        return this.name;
    }

    public void addScorePoint(int scorePoint) {
        this.scorePoints += scorePoint;
    }

    public void emptyPairs() {
        pairs.clear();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + actionPoints;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((pairs == null) ? 0 : pairs.hashCode());
        result = prime * result + scorePoints;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Player other = (Player) obj;
        if (actionPoints != other.actionPoints)
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (pairs == null) {
            if (other.pairs != null)
                return false;
        } else if (!pairs.equals(other.pairs))
            return false;
        if (scorePoints != other.scorePoints)
            return false;
        return true;
    }

    @Override
    public String toString() {
        return name + "("+ getScorePoints() + ") ("+ getActionPoints() +")";
    }
}
